# -*- coding:utf-8 -*-
# @Time:2024/4/1921:01
# @Author:miuzg
# @FileName:new test2.py
# @Software:PyCharm
import requests
import pickle

url = 'http://pyhton.zzhitong.com'

# 给pwd传值zzt666
data = {'pwd':'zzt666'}

# post请求可以携带参数
res = requests.get(url,data=data)

# 获取登录信息
json_data = res.json()
print(json_data)

if json_data['msg']=='登陆成功':
    print('登录成功')
    print(res.cookies)# 输出cookies值

    # 创建cookie文件
    with open('zzt.cookie','wb')as f:
        pickle.dump(res.cookies,f)

    # 读取cookie文件
    with open('zzt.cookies','rb')as f:
        cookie = pickle.load(f)

# 发送请求时，带上cookie信息
res = requests.get('https://python.zzhitong.com/#html',cookies = cookie)
print(res.text)
with open('官网课件.html','w',encoding='utf-8')as f:
    f.write(res.text)
